How to use ternary operator in JavaScript